//
//  RegisterViewController.m
//  Fragrance
//
//  Created by dllo on 15/5/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 80, 50)] ;
    label1.text = @"用户名:";
    label1.layer.cornerRadius = 10;
    label1.layer.masksToBounds = YES;
    [self.view addSubview:label1];
    userNameTF = [[UITextField alloc] initWithFrame:CGRectMake(120, 50, 200, 50)];
    userNameTF.backgroundColor = [UIColor clearColor];
    userNameTF.borderStyle = UITextBorderStyleRoundedRect;
    userNameTF.placeholder = @"请输入用户名";
    userNameTF.delegate = self;
    [self.view addSubview:userNameTF];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 110, 80, 50)];
    label2.text = @"密码:";
    label2.layer.cornerRadius = 10;
    label2.layer.masksToBounds = YES;
    [self.view addSubview:label2];
    password = [[UITextField alloc] initWithFrame:CGRectMake(120, 110, 200, 50)];
    password.backgroundColor = [UIColor clearColor];
    password.borderStyle = UITextBorderStyleRoundedRect;
    password.placeholder = @"请输入密码";
    password.secureTextEntry = YES;
    password.delegate = self;
    [self.view addSubview:password];
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(20, 170, 80, 50)];
    label3.text = @"确认密码:";
    label3.layer.cornerRadius = 10;
    label3.layer.masksToBounds = YES;
    [self.view addSubview:label3];
    password1 = [[UITextField alloc] initWithFrame:CGRectMake(120, 170, 200, 50)];
    password1.backgroundColor = [UIColor clearColor];
    password1.borderStyle = UITextBorderStyleRoundedRect;
    password1.placeholder = @"请再输入密码";
    password1.secureTextEntry = YES;
    password1.delegate = self;
    [self.view addSubview:password1];
    
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(20, 230, 80, 50)];
    label4.text = @"邮箱:";
    label4.layer.cornerRadius = 10;
    label4.layer.masksToBounds = YES;
    [self.view addSubview:label4];
    mailBox = [[UITextField alloc] initWithFrame:CGRectMake(120, 230, 200, 50)];
    mailBox.backgroundColor = [UIColor clearColor];
    mailBox.borderStyle = UITextBorderStyleRoundedRect;
    mailBox.placeholder = @"请输入邮箱";
    mailBox.delegate = self;
    [self.view addSubview:mailBox];
    
    UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(20, 290, 80, 50)];
    label5.text = @"手机号:";
    label5.layer.cornerRadius = 10;
    label5.layer.masksToBounds = YES;
    [self.view addSubview:label5];
    phoneNum = [[UITextField alloc] initWithFrame:CGRectMake(120, 290, 200, 50)];
    phoneNum.backgroundColor = [UIColor clearColor];
    phoneNum.borderStyle = UITextBorderStyleRoundedRect;
    phoneNum.placeholder = @"请输入手机号";
    phoneNum.delegate = self;
    [self.view addSubview:phoneNum];
    
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.frame = CGRectMake(80, 350, 80, 40);
    registerButton.backgroundColor = [UIColor greenColor];
    [registerButton setTitle:@"提交" forState: UIControlStateNormal];
    registerButton.layer.cornerRadius = 10;
    registerButton.layer.masksToBounds = YES;
    [self.view addSubview:registerButton];
    [registerButton addTarget:self action:@selector(touchRegister) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *reWriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    reWriteButton.frame = CGRectMake(200, 350, 80, 40);
    reWriteButton.backgroundColor = [UIColor greenColor];
    [reWriteButton setTitle:@"重填" forState: UIControlStateNormal];
    reWriteButton.layer.cornerRadius = 10;
    reWriteButton.layer.masksToBounds = YES;
    [self.view addSubview:reWriteButton];
    [reWriteButton addTarget:self action:@selector(touchReWrite) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [userNameTF resignFirstResponder];
    [password resignFirstResponder];
    [password1 resignFirstResponder];
    [mailBox resignFirstResponder];
    [phoneNum resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    [userNameTF resignFirstResponder];
    [password resignFirstResponder];
    [password1 resignFirstResponder];
    [mailBox resignFirstResponder];
    [phoneNum resignFirstResponder];
    
    if (userNameTF.text.length == 0 || password1.text.length == 0 || password.text.length == 0 || mailBox.text.length == 0 || phoneNum.text.length == 0) {
        
        UIAlertView *alt = [[UIAlertView alloc] initWithTitle:@"友情提示" message:@"请输入完整信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alt show];
       
    }
    return YES;
    
}

- (void)touchRegister
{
    
}

- (void)touchReWrite
{
    userNameTF.text = @"";
    password.text = @"";
    password1.text = @"";
    mailBox.text = @"";
    phoneNum.text = @"";
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
